/*返回顶部*/
/*返回顶部上下移动，点击返回顶部*/
let returnTop=document.getElementsByClassName("returnTop")[0];

document.addEventListener('scroll',function(){
    let topJuLi = document.documentElement.scrollTop;
    if(topJuLi > 300) {
        returnTop.style.display = "block";
    } else {
        returnTop.style.display = "none";
    }
},true);
returnTop.addEventListener('click',function(){
    turnTop();
},true)
function turnTop() {
    let backTopTimer = setInterval(function() {
        let topH = document.documentElement.scrollTop || document.body.scrollTop;
        let backTopSpeed = Math.floor(-topH / 8);
        if(topH > 0) {
            document.documentElement.scrollTop = document.body.scrollTop = topH + backTopSpeed;
        } else {
            clearInterval(backTopTimer);
        }
    }, 10);
}
setInterval(function(){
    moveTopBottom();
},600);
function moveTopBottom(){
    returnTop.style.bottom="120px";
    setTimeout(function(){
        returnTop.style.bottom="100px";
    },300)
}
/*点击下面的标签返回不同位置*/
let  differentLabel=document.getElementsByClassName(" differentLabel");
let tenLabel=document.getElementsByClassName("tenLabel");
/*生活标签*/
for(let i=0;i<9;i++){
    tenLabel[i].onclick=function(){
        returnPosition(differentLabel[i].offsetTop-60);
        returnPositionX(differentLabel[i].offsetTop-60);
    }
}
tenLabel[9].onclick=function(){
    returnPosition(differentLabel[8].offsetTop-10);
    returnPositionX(differentLabel[8].offsetTop-10);
}

function returnPosition(e) {
    let backTopTimer = setInterval(function() {
        let topH = document.documentElement.scrollTop || document.body.scrollTop;
        // let backTopSpeed = Math.floor(-topH / 8);
        if(topH > e) {
            document.documentElement.scrollTop = document.body.scrollTop = topH -30;
        }else{
            clearInterval(backTopTimer);
        }
    }, 10);
}
function returnPositionX(e) {
    let backTopTimer = setInterval(function() {
        let topH = document.documentElement.scrollTop || document.body.scrollTop;
        // let backTopSpeed = Math.floor(-topH / 8);
        if(topH < e) {
            document.documentElement.scrollTop = document.body.scrollTop = topH +30;
        }else{
            clearInterval(backTopTimer);
        }
    }, 10);
}
function positionBackgroundColor(e){
    for(let i=0;i<10;i++) tenLabel[i].style.backgroundColor="";
    for(let i=0;i<10;i++) tenLabel[i].style.color="black";
    tenLabel[e].style.backgroundColor="#42bbfd";
    tenLabel[e].style.color="#ffffff";
}
tenLabel[0].style.backgroundColor="#42bbfd";
tenLabel[0].style.color="#ffffff";
document.onscroll=function(){
    for(let i=0;i<9;i++){
        let topJuLi = document.documentElement.scrollTop;
        if(topJuLi>=differentLabel[i].offsetTop-122&&topJuLi<=differentLabel[i+1].offsetTop-122)positionBackgroundColor(i);
    }
    let topJuLi = document.documentElement.scrollTop;
    if(topJuLi>=differentLabel[8].offsetTop-10)positionBackgroundColor(9);
}
let spaceContent=document.getElementsByClassName("spaceContent");
for(let i=0;i<spaceContent.length;i++){
    let re1 = new RegExp("<.+?>","g");//匹配html标签的正则表达式，"g"是搜索匹配多个符合的内容
    let msg = spaceContent[i].innerText.replace(re1,'');//执行替换成空字符
    spaceContent[i].innerHTML=msg;
}
// let twoSpace=document.getElementsByClassName("twoSpace");
// for(let i=0;i<twoSpace.length;i++){
//     twoSpace[i].onclick=function(){
//         // location.href=this.getAttribute('href');
//     }
// }